
<template>
    <el-form 
    
    ref="form" 
   
    :model="form" 
    
    label-width="80px" 
    enctype="multipart/form-data" >
        
        
        <el-form-item 
        label="原密码"
       
         >
            <el-input  v-model="form.oldsecret" ></el-input>
        </el-form-item>

        <el-form-item 
        label="新密码"
       
         >
            <el-input  v-model="form.newsecret" ></el-input>
        </el-form-item>

        
        


        
        

        
        
        
        
        <!-- <Editor @getEditorData="getEditorData"></Editor> -->


        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
        </el-form-item>
    </el-form>
</template>


<script>
import axios from 'axios'
import { mapState } from 'vuex'
import Editor from 'index/components/Editor'


export default {
    name:'ProcutForm', 
    inject:['reload'], 
    components:{
        Editor 
    },
    data() {
        return {
            
           
            editorData: '',
            form: {
                oldsecret: '',
                
                newsecret:'',
               
            },
            formData: new FormData(),
           
        }
    },
    activated() {
        this.install()
        
    },
    computed:{
        ...mapState(['baseUrl','scope','zuzhang_scope','userName'])
    },
    methods: {
        install(){
            this.findScope()
            this.getAllLeader()
          
          
        },
     
     
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        deleteLocalStorage (key){
            return localStorage.removeItem(key);
        },
       
        onSubmit() {
             let that = this
            
           
           
            var oldsecret = this.form.oldsecret;
            var newsecret = this.form.newsecret;
            var nickname = this.userName;
           
            if(oldsecret==''||newsecret==''){
                const h = this.$createElement;

                this.$notify({
                title: '警告',
                type: 'warning',
                offset: 100,
                message: h('i', { style: 'color: teal'}, '所有信息必须填写')
                });
                return false;
            }
            //下面append的东西就会到form表单数据的fields中；
            that.formData.append('oldsecret', oldsecret);
            that.formData.append('newsecret', newsecret);
            that.formData.append('nickname', nickname);
            let config = {
                headers: {
                    'Content-Type': 'multipart/form-data'    
                },  
            }
            axios.post(this.baseUrl+"cms/changePassword", this.formData, config).then(function(result) {
                            if(result.data===1){
                                that.$alert('修改成功', '特别提示', {
                                confirmButtonText: '确定',
                                closeOnClickModal:true,
                                center:true,
                                callback: action => {
                                    that.reload();
                                    that.deleteLocalStorage('token');
                                    that.deleteLocalStorage('currentPage');
                                    that.$router.push('/')
                                    that.$message({
                                    message: '恭喜你，密码修改成功',
                                    type: 'success',
                                    duration:'3000',
                                    showClose:true,
                                    });
                                }
                            });
                                
                            }else if(result.data===0){
                                that.$alert('密码错误修改失败', '特别提示', {
                                confirmButtonText: '确定',
                                closeOnClickModal:true,
                                center:true,
                                callback: action => {
                                    that.reload();
                                    that.$message({
                                    message: '密码错误修改失败',
                                    type: 'error',
                                    duration:'3000',
                                    showClose:true,
                                    });
                                }
                            });
                            }

                            
            })
            

        }
       
    }
}
</script>
<style lang="stylus">
.el-message-box__wrapper
    z-index 20003!important
</style>
